<template>
	<view class="content">
		<!-- <view class="swiper">
			<view class="swiper-item">
				<image src="../../static/23aed716-dc4b-408b-8ac5-c6af43a55809.jpg"></image>
			</view>
		</view> -->
		<u-card  :show-head="false" sub-title="一键预约"  @click="goReserve(listV)" >
			<template v-slot:body>
				<view v-if="listV.plateNo">
					<uni-row>
						<uni-col :span="18">
							<view class="owner" >{{ listV.owner }} : {{ listV.plateNo }}</view>
						</uni-col>
						<uni-col :span="6">
							<u-button  type="primary" :plain="true" @click="goReserve(listV)">快捷预约</u-button>
						</uni-col>
					</uni-row>
				</view>
				<view v-else class="bangCar">
					请绑定爱车
				</view>
			</template>
		</u-card>	
		<u-card title="待处理预约" v-if="orderList.length>0">
			<template v-slot:body>
				<view style="padding-bottom: 20rpx;" v-if="listV.plateNo" v-for="(x,i) in orderList" :key="i">
					<uni-row  :gutter="30">
						<uni-col :span="6">
							<view >{{ x.contactName }}</view>
						</uni-col>
						<uni-col :span="12">
							<view > {{ x.plateNo }}</view>
						</uni-col>
						<uni-col :span="6" >
							<u-button size="mini" type="primary" :plain="true" @click="lookInfo(x)">去 处 理</u-button>
						</uni-col>
					</uni-row>
				</view>
			</template>
		</u-card>	
	</view>
</template>

<script>
	export default {
		data() {
			return {
				openid:uni.getStorageSync('openid'),
				list:[],
				listV:{
					plateNo:"",
					owner:""
				},
				orderList:[],
				source:uni.getSystemInfoSync().uniPlatform,
				baseFormData:{},
				isAdmin:1,
			}
		},
		onLoad() {
			console.log(getApp());
			console.log(uni.getSystemInfoSync().uniPlatform,'platformplatformplatform');
			uni.setStorageSync("source",uni.getSystemInfoSync().uniPlatform)
			// #ifdef MP-WEIXIN
			   this.source = "weixin"
			// #endif
			
			// #ifdef H5
			   this.source = "H5"
			// #endif
			
			// #ifdef MP-ALIPAY
			   this.source = "alipay"
			// #endif
			if(!this.openid){
				uni.login({
					success:(res)=>{
						uni.request({
							url: 'wxApp/login',
							method:"GET",
							header: {
							    source:this.source,
							},
							data:{
								code:res.code
							},
							success: (res1) => {
								const openid = res1.data.data.openid;
								this.openid = openid;
								uni.setStorageSync('openid',openid);
								this.getVehicle();
							}
						})
					}
				})
			}else{
				this.getUserInfo();
			}
			uni.showShareMenu({
				withShareTicket: true,
				menus: ['shareAppMessage', 'shareTimeline']
		    })
		},
		onShow() {
			this.getVehicle();
			this.getUserInfo();
			if(this.isAdmin == 2){
				this.getOrderList();
			}
		},
		methods: {
			lookInfo(row){
				uni.navigateTo({
					url: "/pages/reserve/reserveInfo?id="+row.id,
				})
			},
			getOrderList(){
				uni.request({
					url:  "reserve/list",
					method: "POST",
					data: {
						pageNum: 1,
						pageSize: 20,
						status:0
					},
					success: (res) => {
						this.orderList = res.data.list;
				
					}
				})
			},
			getPhoneNumber(e){
				console.log(e.detail.code)  // 动态令牌
				uni.request({
					url:  "wxApp/getuserphonenumber?code="+e.detail.code,
					method:"GET",
					success:(res)=> {
						//手机号
						console.log(res.data.data.phone_info.purePhoneNumber);
						uni.request({
							url:  "owner/updateMobileByOpenid?code="+e.detail.code,
							method:"POST",
							data:{
								openid:this.openid,
								purePhoneNumber:res.data.data.phone_info.purePhoneNumber
							},
							success:(res)=> {
								
							}
						})
						
					}
				})
			},
			getUserInfo(){
				uni.request({
					url:"owner/getUserInfo",
					method:"POST",
					data:{
						source:this.source,
						openid:this.openid
					},
					success:(res)=> {
						this.baseFormData = {
							...res.data.data,
						}
						
						if(res.data.data.ownerMobile && res.data.data.ownerName){
							uni.setStorageSync('ownerMobile',res.data.data.ownerMobile);
							uni.setStorageSync('ownerName',res.data.data.ownerName);
							uni.setStorageSync('ownerId',res.data.data.id);
						}else{
							uni.navigateTo({
								url: "/pages/user/register",
							})
						}
						this.isAdmin = res.data.data.admin;
						uni.setStorageSync('isAdmin',this.isAdmin);
						if(this.isAdmin == 2){
							this.getOrderList();
						}
					}
				})
			},
			getVehicle(){
				uni.request({
					url: "vehicle/getVehicle?openid="+this.openid,
					method:"GET",
					success:(res)=> {
						if(res.data.data){
							this.listV = res.data.data;
						}
					}
				})
			},
			goReserve(objParam) {
				if(objParam.plateNo){
					const encodedParam = encodeURIComponent(JSON.stringify(objParam));
					uni.navigateTo({
						url: "/pages/reserve/add?param="+ encodedParam,
					})
				}else{
					uni.navigateTo({
						url: "/pages/vehicle/vehicle",
					})
				}
				
			}
		}
	}
</script>

<style scoped lang="less">
	.content{
		background: #f8f8f9;
		.owner{
			font-size: 40rpx;
			padding-top: 10rpx;
		}
		.title{
			margin-left: 30rpx;
			font-size: 40rpx;
			font-weight: bold;
			padding-top: 20rpx;
		}
		.u-card{
			font-weight: bold;
			// background-color: goldenrod;
			// :deep(.u-card__head.u-border-bottom){
			// 	background-color: goldenrod;
			// 	color: #fff;
			// }
		}
		.bangCar{
			text-align: center;
		}
	}
	.parts-row{
		padding:0 30rpx;
		margin-top: 20rpx;
		.parts{
			margin: 20rpx 0;
			background: #fff;
			.image{
				width:300rpx;
				height: 200rpx;
			}
			.text{
				text-align: center;
				font-size: 30rpx;
				padding: 20rpx 0;
			}
		}
	}
	.u-body-item{
		font-size: 30rpx;
		padding: 20rpx 0;
	}
	
	.swiper {
		background: #fff;
		padding: 0 20rpx;
		height: 360rpx;
		margin-top: 20rpx;

		.swiper-item {
			border-radius: 10rpx;
			overflow: hidden;
			height: 360rpx;

			image {
				width: 100%;
				height: 100%;
				border: 1px solid rgba(127, 102, 157, .5);
				border-radius: 18rpx;
				background: rgba(252, 250, 255, 1);
				box-shadow: 0 0 5px .5px rgba(127, 102, 157, .2);
			}
		}
	}
</style>